﻿namespace QMVnSoft.Controls.ChildGridControls
{
    using System;
    using System.Windows.Forms;

    public class DateColumn : DataGridViewColumn
    {
        public DateColumn() : base(new DateCell())
        {
            this.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
        }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                DateCell cell = value as DateCell;
                if ((value != null) && (cell == null))
                {
                    throw new InvalidCastException("Value provided for CellTemplate must be of type DataGridViewTextOptionElements.DataGridViewTextOptionCell or derive from it.");
                }
                base.CellTemplate = value;
            }
        }

        private DateCell DateCellTemplate
        {
            get
            {
                return (DateCell) base.CellTemplate;
            }
            set
            {
                if ((value != null) && !value.GetType().IsAssignableFrom(typeof(DateCell)))
                {
                    throw new InvalidCastException("Must be a CustomDataGridViewOptionTextBoxCell");
                }
                base.CellTemplate = value;
            }
        }
    }
}

